import React, { useMemo, useState } from 'react';

function slowMulti(n: number) {
	const now = performance.now();
	while (performance.now() - now < 1000) { }
	return n * 2;
}

const useMemo2 = () => {
	const [count, setCount] = useState(0);
	const [count2, setCount2] = useState('');

	const cc = useMemo(() => slowMulti(count), [count]);
	return (
		<div>
			<div>count:{count}</div>
			<div>count2:{count2}</div>
			<button className='p-4 bg-green-600 text-white' onClick={() => {
				setCount(c => c + 1);
			}}>get</button>
			<button onClick={() => {
				setCount2(cc + Date.now().toString());
				console.log('executed');
			}}>decrease</button>
		</div>
	);
};

export default useMemo2;